package kotlinquanweizhinan.chapt4函数.醉酒状态报告
fun main(){
    val name = "Madrigal"
    val healthPoints = 80
    val isBlessed = true //是否走运
    val isImmortal = false //记录玩家是否永生

    val auraColor = auraColor(isBlessed, healthPoints, isImmortal)

    //使用string横版
    println("(Aura:$auraColor) "+ "(Blessed:${if(isBlessed) "YES" else "NO"})")
    printPlayerStatus(healthPoints, isBlessed, name)

   // castFireball()
    println(castFireball(50))
}

//单表达式函数
private fun printPlayerStatus(healthPoints: Int, isBlessed: Boolean, name: String) =
    println(name + "" + formatHealthStatus(healthPoints,isBlessed))

//单表达式函数
private fun auraColor(isBlessed: Boolean, healthPoints: Int, isImmortal: Boolean)=
    if (isBlessed && healthPoints > 50 || isImmortal) "GREEN" else "NONE"

//单表达式函数
private fun formatHealthStatus(healthPoints: Int, isBlessed: Boolean)=
    when (healthPoints) {
        100 -> "is in excellent conditioin!"
        in 90..99 -> "has a few scrateches."
        in 75..89 -> if (isBlessed) {
            "has some minor woonds but is healing quite quickly!"
        } else {
            " has some minor wounds."
        }
        in 15..74 -> " looks pretty hurt."
        else -> "is in awful condition!"
    }

//单表达式函数


private fun castFireball(numFireballs: Int=2)=
    when(numFireballs){
        in 1..10 -> "tipsy(微醺)"
        in 11..20 ->"sloshed(微醉)"
        in 21..30 ->"soused(醉了)"
        in 31..40 -> "stewed(大醉)"
        else -> "烂醉如泥"
    }
